faApp.controller('ShopUserCtrl', ['$scope', 'shopService', '$location', '$rootScope', '$controller', '$route', '$routeParams', 'exportService', 'licaishiManagerService', 'sessionService','$cookieStore','$cookies', function ($scope, shopService, $location, $rootScope, $controller, $route, $routeParams, exportService, licaishiManagerService, sessionService,$cookieStore,$cookies) {
    $scope.ctrlName = "ShopUserCtrl";
    $controller('BaseListCtrl', {$scope: $scope});
    $scope.fas = [];
    $scope.black = {blackType: 1};
    $scope.vtype = "";
    if ($routeParams.orderFlag == "1" && $routeParams.notHasVisit) {
        $scope.vtype = "成交客户列表";
    } else if ($routeParams.orderFlag == "2" && $routeParams.notHasVisit) {
        $scope.vtype = "待沉寂理财师列表";
    } else if ($routeParams.notHasVisit) {
        $scope.vtype = "待回访理财师列表";
    } else if ($routeParams.notHasCheck) {
        $scope.vtype = "待审核理财师列表";
    } else if ($routeParams.isnoManagerUserLicaishi) {
        $scope.vtype = "待分配理财师列表";
    } else {
        $scope.vtype = "所有理财师列表";
    }

    if($routeParams.newPage){
        console.info($routeParams.isEmptyParam)
        if($routeParams.isEmptyParam){
            $scope.searchMap={isnoManagerUserLicaishi:"",notHasVisit:""
                ,notHasCheck:"",orderFlag:"",systemUserId:"",visitModel:"",systemUserId2:"",
                "pageSize" : 20,   "pageNo" : 1
            };
            $scope.config={isnoManagerUserLicaishi:"",notHasVisit:""
                ,notHasCheck:"",orderFlag:"",systemUserId:"",visitModel:"",
                "pageSize" : 20,   "pageNo" : 1
            };
        }
        $scope.listWhere="";
        if($routeParams.isnoManagerUserLicaishi){//待分配
            $scope.searchMap.isnoManagerUserLicaishi=$routeParams.isnoManagerUserLicaishi;
            $scope.config.isnoManagerUserLicaishi=$routeParams.isnoManagerUserLicaishi;
            $scope.listWhere=$scope.listWhere+"&isnoManagerUserLicaishi="+$routeParams.isnoManagerUserLicaishi;
        }
        if($routeParams.notHasVisit){//是否回访
            $scope.searchMap.notHasVisit=$routeParams.notHasVisit;
            $scope.config.notHasVisit=$routeParams.notHasVisit;
            $scope.listWhere=$scope.listWhere+"&notHasVisit="+$routeParams.notHasVisit;
        }
        if($routeParams.notHasCheck){//待审核
            $scope.searchMap.notHasCheck=$routeParams.notHasCheck;
            $scope.config.notHasCheck=$routeParams.notHasCheck;
            $scope.listWhere=$scope.listWhere+"&notHasCheck="+$routeParams.notHasCheck;
        }
        if($routeParams.orderFlag){//是否交易    1 成交客户
            $scope.searchMap.orderFlag=$routeParams.orderFlag;
            $scope.config.orderFlag=$routeParams.orderFlag;
            $scope.config.showOrderFlag=true;
            $scope.listWhere=$scope.listWhere+"&orderFlag="+$routeParams.orderFlag;
        }
        console.info($routeParams.systemUserId)
        if($routeParams.systemUserId){//当前用户ID  我的客户列表
            $scope.searchMap.systemUserId=$routeParams.systemUserId;
            $scope.config.systemUserId=$routeParams.systemUserId;
            //$scope.searchMap.systemUserId2=$routeParams.systemUserId;
            $scope.config.showSystemUser=true;
            $scope.listWhere=$scope.listWhere+"&systemUserId="+$routeParams.systemUserId;
        }
        if($routeParams.pageNo){//当前用户ID  我的客户列表
            $scope.searchMap.pageNo=$routeParams.pageNo;
            $scope.config.pageNo=$routeParams.pageNo-0;
        }

        if(($routeParams.orderFlag==2&&$routeParams.notHasVisit)||$routeParams.orderFlag==1){
            $scope.showVisit=true;
            if($routeParams.orderFlag==2&&$routeParams.notHasVisit){
                $scope.showVisitWhere=true;
            }else{
                $scope.showVisitWhere=false;
            }
        }
    }

    $scope.config1 = {"pageSize": 10000};
    var sss = {"userId": "*", "username": "*无服务顾问*"};
    if (!$scope.config.showSystemUser) {
        licaishiManagerService.list($scope.config1).then(function (json) {
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.licaishiManagerUserList = json.list;
                $scope.licaishiManagerUserList.push(sss);
                $scope.loading = false;
            }
        });
    } else {
        licaishiManagerService.otherList($scope.config1).then(function (json) {
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.licaishiManagerUserList = json.list;
                $scope.licaishiManagerUserList.push(sss);
                $scope.loading = false;
            }
        });
    }


    $scope.chkAllLicaishiList = function () {
        if ($("#chkAllLicaishiList").attr("checked") == "checked") {
            $("[name='chkLicaishiList']").attr("checked", "checked");
        } else {
            $("[name='chkLicaishiList']").attr("checked", false);
        }
    }

    $scope.licaishiManage = function (t) {
        chooseLicaishiList(t);
        if ($scope.chooseLicaishiId != undefined && $scope.chooseLicaishiId != "") {
            $scope.chooseLicaishiIdCount = $scope.chooseLicaishiId.split(",").length - 1;
            $scope.isShowLicaishiManagerLayer = true;
        } else {
            alert("请选择理财师！");
            return;
        }
        if (t != undefined && t != "" && t == "1") {
            licaishiManagerService.list({"pageSize": 9999, "pageNo": 1}).then(function (json) {
                if (json.statusCode) {
                    alert("出错了:" + json.statusCode);
                } else {
                    $scope.licaishiManagerUserList2 = json.list;
                }
            });
        }
        $scope.t = t;
    };
    chooseLicaishiList = function (t) {
        $scope.chooseLicaishiId = "";
        $scope.omu = "";
        $("[name='chkLicaishiList']").each(function (i) {
            if ($(this).attr("checked") == "checked") {
                //if(t == 1 && $(this).attr("omu")){
                //  alert("请选择未分配的理财师！");
                //  $scope.chooseLicaishiId = -1;
                //  return false;
                //}else
                if (t == 0 && !$(this).attr("omu")) {
                    alert("请选择已分配的理财师！");
                    $scope.chooseLicaishiId = -2;
                    return false;
                }
                if ($(this).attr("value") != undefined && $(this).attr("value") != "") {
                    $scope.chooseLicaishiId += $(this).attr("value") + ",";
                    $scope.omu += $(this).attr("omu") + ",";
                }
            }
        });
    };
    $scope.managerLicaishi = {};
    $scope.fenpeiOrHuishou = function (t) {
        if ($scope.chooseLicaishiId != null && $scope.chooseLicaishiId != undefined) {
            $scope.managerLicaishi.licaishiIds = $scope.chooseLicaishiId.substring(0, $scope.chooseLicaishiId.length - 1);
        }
        if (t == "1") {
            if ($scope.managerLicaishi.systemUserId != undefined && $scope.managerLicaishi.systemUserId != "" && t != "") {
                // 分配操作
                licaishiManagerService.managerLicaishiUserAdd($scope.managerLicaishi).then(function (json) {
                    if (json.statusCode) {
                        alert("出错了:" + json.statusCode);
                    } else {
                        // 操作成功！分配成功！
                        var _map = json.map;
                        if(_map.not_aCount>0){
                            alert('A类分配超出上限，失败'+_map.not_aCount);
                        }else if(_map.not_okCount>0){
                            alert('OK类分配超出上限，失败'+_map.not_okCount);
                        }else {
                            $scope.alertNextPage("分配成功！");
                        }



                        $route.reload();
                    }
                }, function (res) {
                    alert('网络状态不稳定或超时！');
                });
            } else {
                alert("请选择服务顾问！");
            }
        } else if (t == '0') {
            var tmpid = "";
            angular.forEach($scope.omu.split(","), function (o, i) {
                if (i == 0) {
                    tmpid = o;
                } else {
                    if (o != undefined && o != "" && o != tmpid) {
                        tmpid = "-99";
                    }
                }
            });
            if (tmpid != undefined && tmpid != "-99") {
                // 回收时，理财师服务顾问设为空
                $scope.managerLicaishi.systemUserId = "";
                // 回收
                licaishiManagerService.huishouManagerLicaishiByUser($scope.managerLicaishi).then(function (json) {
                    if (json.statusCode) {
                        alert("出错了:" + json.statusCode);
                    } else {
                        $scope.alertNextPage("回收成功！");
                        $route.reload();
                    }
                });
            } else {
                if (confirm("选择了多个理财师，且服务顾问人不同，确认要同时回收吗！")) {
                    // 回收时，服务理财师设为空
                    $scope.managerLicaishi.systemUserId = "";
                    // 回收
                    licaishiManagerService.huishouManagerLicaishiByUser($scope.managerLicaishi).then(function (json) {
                        if (json.statusCode == "4002") {
                            alert("存在已分配理财师，请先收回，后分配！");
                        } else if (json.statusCode) {
                            alert("出错了:" + json.statusCode);
                        } else {
                            $scope.alertNextPage("回收成功！");
                            $route.reload();
                        }
                    });
                }
            }
        }
    }

    $scope.config['orderBy'] = $routeParams.orderBy || '',
        $scope.config['orderByTag'] = $routeParams.orderByTag || '',

        $rootScope.viewNextBtn = {
            listWhere : $scope.listWhere

        }
    console.log($scope.config)
    $scope.$watch('config',function(){
        if ($scope.watchIsChange()){
            shopService.shopUserList($scope.config).then(function(json){
                $scope.fas = json.list || [];
                $scope.pager = json.pager;
                $rootScope.myKeHuNowPageListSize = json.list || [];
                $rootScope.viewNextBtn.pageNo = $scope.pager.pageNo;
                var arr = [];
                for(t in json.list){
                    arr.push(json.list[t].id);
                }
                $cookies.myKeHuNowPageListSize = angular.toJson(arr);
            });
        }
    },true);
    //读取查询 seeionStronge
    $scope.getLastSearchConfig();
    // $scope.search();

    $scope.orderbyPositionMap = {};
    if (!$routeParams.orderBy && !$routeParams.orderByTag) {
        $scope.orderbyPositionMap['weight'] = "0";
    } else {
        $scope.orderbyPositionMap[$routeParams.orderBy] = "0";
    }
    $scope.orderbyFreqMap = {
        "createDate": ["desc", "asc"],
        "lastLoginTime": ["desc", "asc"],
        "latestVisitTime": ["desc", "asc"],
        "addAuthDate": ["desc", "asc"]
    };
    $scope.orderby = function (field) {
        var freq = $scope.orderbyFreqMap[field];
        var old = $scope.orderbyPositionMap[field];
        $scope.orderbyPositionMap = {};

        if (old == undefined) {
            $scope.orderbyPositionMap[field] = 0;
        } else {
            $scope.orderbyPositionMap[field] = old + 1;
            if ($scope.orderbyPositionMap[field] >= freq.length) {
                $scope.orderbyPositionMap[field] = 0;
            }
        }

        if (field == "weight") {
            $scope.config.orderBy = "";
            $scope.config.orderByTag = "";
        } else {
            $scope.config.orderBy = field;
            $scope.config.orderByTag = freq[$scope.orderbyPositionMap[field]];
        }
    }

    $scope.toViewPage = function (id) {
        var url = 'shop/faauit?id=' + id + $scope.listWhere + '&pageNo=' + $scope.config.pageNo;
        $location.url(url);
    }

    $scope.showBlackAddForm = function (id) {
        $scope.black.userId = id;
        $scope.showBlackAddFormFlag = true;
    };

    //$scope.blackAdd = function(){
    //    if (!$scope.form.$invalid){
    //        faService.blackAdd($scope.black).then(function(json){
    //            if (!json.statusCode){
    //                $scope.addAlert("操作成功");
    //                $route.reload();
    //            }else{
    //                alert("出错了:" + json.statusCode);
    //            }
    //        });
    //    }else{
    //        alert("请先完整填写信息");
    //        return;
    //    }
    //};

    $scope.cert = {id: ""};
    $scope.showCertForm = function (id) {
        $scope.cert.id = id;
        $scope.showCertFormFlag = true;

    };
    //$scope.certSave = function(){
    //    if (!$scope.certform.$invalid){
    //        if ($scope.cert.type && $scope.cert.uRole != "99"){
    //            $scope.cert.uRole = $scope.cert.type;
    //        }
    //        if (!$scope.cert.uRole || ($scope.cert.uRole == "2" && !$scope.cert.type)){
    //            alert("请选择评级");
    //            return;
    //        }
    //        faService.certSave($scope.cert).then(function(json){
    //            if (!json.statusCode){
    //                $scope.addAlert("操作成功");
    //                $route.reload();
    //            }else{
    //                alert("出错了:" + json.statusCode);
    //            }
    //        });
    //    }else{
    //        alert("请先完整填写信息");
    //        return;
    //    }
    //};

    $scope.selectLevelType = function (type) {
        $scope.cert.type = type;
        $scope.cert.uRole = "2";
    };

    $scope.selectRoleResult = function () {
        if ($scope.cert.uRole == "99") {
            $scope.cert.type = "";
        }
    }

    $scope.export = function () {
        exportService.exportCSV($scope.config, "faList_EXPORT");
    };


    $scope.setPageSize = $scope.config.pageSize;

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };
    if ($scope.dictMap.rzMapModel[0].value != 'Y') $scope.dictMap.rzMapModel;


}])

faApp.controller('ShopSucaiCtrl', ['$scope', 'shopService', '$location', '$rootScope', '$controller', '$route', '$routeParams', 'exportService', 'licaishiManagerService', 'sessionService', function ($scope, shopService, $location, $rootScope, $controller, $route, $routeParams, exportService, licaishiManagerService, sessionService) {
    var sucai = {}
    $scope.sucai = sucai;

    $scope.ctrlName = "ShopSucaiCtrl";
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.staticHost=App.staticHost;

    $scope.config['orderBy'] = $routeParams.orderBy || '',
        $scope.config['orderByTag'] = $routeParams.orderByTag || '',

        $scope.$watch('config', function () {
            if ($scope.watchIsChange()) {
                shopService.shopSucaiList($scope.config).then(function (json) {
                    $scope.fas = json.list || [];
                    $scope.pager = json.pager;
                    $rootScope.myKeHuNowPageListSize = json.list || []
                });
            }
        }, true);
    //读取查询 seeionStronge
    $scope.getLastSearchConfig();
    $scope.search();
}])
faApp.controller('ShopSucaiAddCtrl', ['$scope', 'shopService', '$location', '$rootScope', '$controller', '$route', '$routeParams', 'exportService', 'licaishiManagerService', 'sessionService', function ($scope, shopService, $location, $rootScope, $controller, $route, $routeParams, exportService, licaishiManagerService, sessionService) {
    $controller('BaseCtrl', {$scope: $scope});

    $scope.sucai = {"sucaiSort":10};
    $scope.loading = true;

    $scope.onUploadFile({
        showMessage : function(m){ alert(m); },
        onComplete:function(f,response){
            if (response.statusCode == "0000") {
                $scope.sucai.picAddre = App.staticHost + response.attribute.fileUrl;
                $scope.$apply();
            } else {
                alert('上传失败');
            }
        }
    });
}])

faApp.controller('ShopFaViewCtrl',['$rootScope','$scope','faService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,faService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $controller('BaseCtrl', {$scope: $scope});

    $scope.id = $routeParams.id;
    $scope.item = {};
    $scope.visit = {};
    $scope.loading = true;
    $scope.auditOptionMessage = "";
    $scope.aoMsg = false;
    $scope.firstReturnVisitCycle = "";
    $scope.stayAwayFromTheLastVisit = "";

    var myKeHuNow = angular.fromJson($cookies.myKeHuNowPageListSize);

    $scope.listWhere="?newPage=true";
    $scope.vtype="";
    if($routeParams.orderFlag=="1"&&$routeParams.notHasVisit){
        $scope.vtype="成交客户列表";
    }else if($routeParams.orderFlag=="2"&&$routeParams.notHasVisit){
        $scope.vtype="待沉寂理财师列表";
    }else if($routeParams.notHasVisit){
        $scope.vtype="待回访理财师列表";
    }else if($routeParams.notHasCheck){
        $scope.vtype="待审核理财师列表";
    }else if($routeParams.isnoManagerUserLicaishi){
        $scope.vtype="待分配理财师列表";
    }else{
        $scope.vtype="所有理财师列表";
    }
    if($routeParams.isnoManagerUserLicaishi){//待分配
        $scope.listWhere=$scope.listWhere+"&isnoManagerUserLicaishi="+$routeParams.isnoManagerUserLicaishi;
    }
    if($routeParams.notHasVisit){//是否回访
        $scope.listWhere=$scope.listWhere+"&notHasVisit="+$routeParams.notHasVisit;
    }
    if($routeParams.notHasCheck){//待审核
        $scope.listWhere=$scope.listWhere+"&notHasCheck="+$routeParams.notHasCheck;
    }
    if($routeParams.orderFlag){//是否交易    1 成交客户
        $scope.listWhere=$scope.listWhere+"&orderFlag="+$routeParams.orderFlag;
    }
    if($routeParams.systemUserId){//当前用户ID  我的客户列表
        $scope.listWhere=$scope.listWhere+"&systemUserId="+$routeParams.systemUserId;
    }
    if($routeParams.pageNo){//当前用户ID  我的客户列表
        $scope.listWhere=$scope.listWhere+"&pageNo="+$routeParams.pageNo;
    }
    $scope.$watch('id',function(){
        for(m in myKeHuNow){
            if( myKeHuNow[m] == $scope.id ){
                $scope.now = m;
            }
        }
        faService.faShopQuery({id:$scope.id}).then(function(json){
            $scope.item = json.faUserInfo || {};
            $scope.loading = false;
            /**基本 属性**/
            if($scope.item.sourceCode =="")  $scope.item.sourceCode="--";
            if($scope.item.sourceLoginName =="")  $scope.item.uManagerId="--";
            // $scope.item.uManagerId = $scope.item.uManagerId=0 || "--";
            if($scope.item.uManagerId==0) $scope.item.uManagerId="--";


            console.info("认证信息：")
            console.info($scope.item)
            /**审核 属性**/
            $scope.cert.uCompanyName = $scope.item.uCompanyName || "";
            $scope.cert.uCompanyADD = $scope.item.uCompanyADD || "";
            $scope.cert.uJob = $scope.item.uJob || "";
            $scope.cert.uShopRole = $scope.item.uShopRole ;
            $scope.cert.type = $scope.cert.uShopRole;
            $scope.cert.uRealName = $scope.item.uRealName || "";
            $scope.cert.uCompany = $scope.item.uCompany || "";
            if($scope.item.faUserauth){
                $scope.cert.wechatNo = $scope.item.faUserauth.wechatNo || "";
            }
            if($scope.item.uShopRole!="99"){
                //$scope.cert.uShopRole ="2";
            }
            $scope.cert.uAuditOpinion=$scope.item.uAuditOpinion ;
            if($scope.item.uShopRole=="99"&&$scope.cert.uAuditOpinion!="注册手机号码与名片手机号码不一致"&&$scope.cert.uAuditOpinion!="未上传名片或上传名片与资质要求不符"){
                $scope.auditop.auditOptionMessage=$scope.cert.uAuditOpinion;
                $scope.cert.uAuditOpinion="3";
                $scope.aoMsg=true;
            }
            $scope.cert.uSex = $scope.item.uSex;
            $scope.cert.uEmail = $scope.item.uEmail || "";
            $scope.cert.auditRemarks = $scope.item.auditRemarks || "";
            $scope.cert.uCardType = $scope.item.uCardType || "";
        });
    },true)

    $scope.isShowVisitLayer = false;
    $scope.isShowCheckFaUser = true;
    $scope.visitList = [];

    $scope.cert = {};
    $scope.auditop={};
    $scope.certSave = function(){
        $scope.cert.id = $scope.id
        if (!$scope.certform.$invalid){
            //if ($scope.cert.type && $scope.cert.uShopRole != "99"){
            //    $scope.cert.uShopRole = $scope.cert.type;
            //}
            //if (!$scope.cert.uShopRole || ($scope.cert.uShopRole == "2" && !$scope.cert.type)){
            //    alert("请选择评级");
            //    return;
            //}
            if ($scope.cert.uShopRole=='2'||$scope.cert.uShopRole=='99'){
            } else {
                alert("请选择认证情况！");
                return;
            }
            //if($scope.aoMsg&&$scope.cert.uShopRole == 99){
            //    if(!$scope.auditop.auditOptionMessage){
            //        alert("请填写未通过原因！");
            //        return;
            //    }
            //    $scope.cert.uAuditOpinion = $scope.auditop.auditOptionMessage;
            //}
            faService.shopCertSave($scope.cert).then(function(json){
                if (!json.statusCode){
                    if($scope.isNewCompany && $scope.newCompanyName){
                        faService.sanfangAdd({tpcFullName: $scope.newCompanyName}).then(function(json){
                            console.log(json);
                        });
                    }

                    $scope.addAlert("操作成功");
                    alert("操作成功！")
                    $location.url("/shop/falist"+$scope.listWhere);
                }else{
                    alert("出错了:" + json.statusCode);
                }
            });
        }else{
            alert("请先完整填写信息");
            return;
        }
    };

    $scope.selectLevelType = function(type){
        $scope.cert.type = type;
        $scope.cert.uShopRole = "2";
    };
    $scope.selectCustomerLable = function(type){
        $scope.visit.customerLable = type;
    };
    $scope.selectRoleResult = function(){
        if ($scope.cert.uShopRole == "99"){
            $scope.cert.type = "1";
            $scope.cert.uAuditOpinion="";
        }else{
            $scope.cert.type = "";

        }
    };

    $scope.auditOption = function(){
        if($scope.cert.uAuditOpinion == "3"){
            $scope.aoMsg = true;
        }else{
            $scope.aoMsg = false;
        }
    };

    $scope.markFaUser = function(){
        if($scope.id){
            faService.markFaUser($scope.id).then(function(json){
                if (json.statusCode){
                    alert("出错了:" + json.statusCode);
                }else{
                    $scope.companyInvitationCode = json.cic;
                    alert("标记成功！");
                }
            });
        }else{
            alert("系统异常，请刷新页面重试！");
        }
    }
}]);

faApp.controller('BehaviorHomeCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $controller('BaseCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.data = null;

    function queryData(){
        shopService.getBehaviorHomeList({data:$scope.data}).then(function(json){
            console.info(json)
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{
                $scope.behaviorHomeList=json.list;

            }
        });
    }
    queryData();

    $scope.queryList = function(){
        queryData();
    }
}]);
faApp.controller('BehaviorProdCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $controller('BaseCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.data = null;

    function queryData(){
        shopService.getBehaviorProdList({data:$scope.data}).then(function(json){
            console.info(json)
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{
                $scope.behaviorProdList=json.list;

            }
        });
    }
    queryData();

    $scope.queryList = function(){
        queryData();
    }
}]);
faApp.controller('BehaviorCustCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $scope.loading = true;
    $scope.data = null;

    function queryData(){
        shopService.getBehaviorCustList({data:$scope.data}).then(function(json){
            console.info(json)
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{
                $scope.behaviorCustList=json.list;

            }
        });
    }
    queryData();

    $scope.queryList = function(){
        queryData();
    }
}]);
faApp.controller('BehaviorFpCtrl',['$rootScope','$scope','shopService','$location',
    '$controller','$routeParams','$route','$cookies'
    ,function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies) {

    $controller('BaseListCtrl', {$scope: $scope});

     $scope.list = [];
    $scope.loading = true;
    $scope.data = null;
    $scope.getIn = 1;
    var searchData = {}
    $scope.faName = null;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1,
        "data" :$scope.data,
        "getIn" :$scope.getIn,
        "faName" :$scope.faName
    }

    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        shopService.getBehaviorFpList($scope.config).then(function (json) {

            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{
                $scope.behaviorFpList=json.list;
                $scope.pager = json.pager;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);


    $scope.queryList = function(){
        $scope.config.getIn = $scope.getIn;
        $scope.config.data = $scope.data;
        $scope.config.faName = $scope.faName;
    }

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };
}]);
faApp.controller('BehaviorFooterMenuCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $controller('BaseCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.data = null;

    function queryData(){
        shopService.getBehaviorFooterMenuList({data:$scope.data}).then(function(json){
            console.info(json)
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{
                $scope.behaviorFooterMenuList=json.list;

            }
        });
    }
    queryData();

    $scope.queryList = function(){
        queryData();
    }
}]);

//店招列表
faApp.controller('ShopBackGroundList',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {
    $controller('BaseListCtrl', { $scope: $scope });
    $scope.loading = true;
    $scope.data = null;
    $scope.listOne =[];
    $scope.listTwo =[];
    shopService.getShopBackGroundList({data:$scope.data}).then(function(json){
        console.info(json)
        if (json.statusCode){
            alert("出错了:" + json.statusCode);
        }else{
            json.list;
            for(var i=0;i<json.list.length;i++){
                if(json.list[i].type==1 ){
                    $scope.listOne.push(json.list[i])
                }else{
                    $scope.listTwo.push(json.list[i])
                }
            }

        }
    });


    $scope.save = function(id,t,imgSrc){
        var src =""
        if(imgSrc!=undefined && imgSrc.length>0){
            src = imgSrc;
        }
        if(src.length<=0) {
            if (!confirm("确认删除吗？")) {
                return false;
            }
        }
        shopService.getShopBackGroundAdd({id:id,backgroudImg:src}).then(function(json){
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{

                if(src.length==0){
                    $("#"+t).attr('src','');
                }
                alert("成功");
                $route.reload();
            }
        });

    }

    $scope.getId = function(id){
        $("#getId").val(id);
    }

    $scope.onUploadFile({
        showMessage: function(m) { alert(m); },
        type:'shopBackground',
        onComplete: function(f, response, id) {
            id--;
            if (response.statusCode == "0000") {
                $("#"+id).attr('src',response.attribute.fileUrl);
                var getId=$("#getId").val();
                $scope.save(getId,id,response.attribute.fileUrl);
            } else {
                alert('上传失败');
            }
        }
    });


}]);



faApp.controller('ShopUserFeedBackList',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout) {

    $controller('BaseCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            shopService.getShopUserFeedBackList($scope.config).then(function (json) {

                if (json.statusCode) {
                    alert("出错了:" + json.statusCode);
                } else {
                    $scope.list = json.list;
                    $scope.pager = json.pager;
                    $scope.loading = false;
                }
            });
        }
    },true);

    var phones="";
    $scope.showDiv = function(id, phone){

        $scope.showCon=true;
        phones = phone;
        shopService.getShopUserFeedBackList($scope.config).then(function (json) {

            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                // $scope.list = json.list;
                angular.forEach(json.list,function(o){
                    if(o.fpUserPhone==phone){
                        var html = "";
                        var backList = [];

                        backList = o.backList;
                        for(var k = 0;k<backList.length;k++){
                            if(backList[k].type==0){
                                html+="<div style='float: left;margin-top: 15px'>用户"+backList[k].fpUserPhone+"：</div><div style='float: left;width: 300px;text-align:left;word-break: break-all;word-wrap: break-word;margin-top: 15px;background-color: #F5F5F5 '>"+ backList[k].content+"</div>";
                            }else{
                                html+="<div style='float: right;margin-top: 15px;clear: both'>：客服</div><div style='float: right;width: 450px;text-align:right;word-break: break-all;word-wrap: break-word;margin-top: 15px;'>"+ backList[k].content+"</div>";
                            }
                        }
                        $("#showContent").html(html);
                        $("#showContent").scrollTop($('#showContent')[0].scrollHeight);
                    }
                });
            }
        });

    };

    var feedBack = {}
    $scope.feedBack = feedBack;
    feedBack.item = {}
    $scope.addFeeBack = function () {
        if(phones.length>0) {
            feedBack.item.fpUserPhone = phones;
        }
        feedBack.item.type='1';
        shopService.getShopUserFeedBackADD(feedBack.item).then(function(json){
            console.info(json)
            if (json.statusCode){
                alert("出错了:" + json.statusCode);
            }else{

                var list = $scope.list;
                for(var c =0;c<list.length;c++){
                    if(list[c].fpUserPhone==phones){
                        list[c].backList.push(feedBack.item);
                        list[c].content=feedBack.item.content;
                    }
                }

                $("#showContent").html($("#showContent").html()+
                    "<br/><div style='float: right;margin-top:15px;clear:both'>：客服</div><div style='width: 450px;float: right;text-align:right;word-break: break-all;word-wrap: break-word;margin-top:15px'>"+
                    feedBack.item.content+"</div>");
                feedBack.item = {}

            }
        });
    }
}]);
faApp.controller('ShopSubjectListCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 10,
        "pageNo" : 1
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        shopService.getShopSubjectList($scope.config).then(function (json) {

            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.list = json.list;
                for(var i=0; i<$scope.list.length; i++) {
                    $scope.list[i].answer = eval('('+$scope.list[i].answer+')')
                }
                $scope.pager = json.pager;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);


    //新增答题
    {
        $scope.showaddanswer = false;

        //初始化新增答案
        function initAddAanwer() {
            $scope.answerarr = [];
            var item = {};
            item.subno = 'A';
            $scope.answerarr.push(item);

            $scope.subjectitem = {};
        }

        //新增答案
        $scope.addAnswer = function(){
            if($scope.answerarr.length==26) {
                alert("不能添加更多了！");
                return false;
            }

            var item = {};
            item.subno = $filter('answeNum')($scope.answerarr.length+1);
            $scope.answerarr.push(item);
        }


        //删除答案
        $scope.delAnswer = function(id){
            if(confirm("确认删除吗？")) {
                $scope.answerarr.splice(id,1);

                for(var i=0; i<$scope.answerarr.length; i++) {
                    $scope.answerarr[i].subno = $filter('answeNum')(i+1);
                }
            }
        }

        //打开新增答案窗口
        $scope.addnewanswer = function(){
            $scope.showaddanswer = true;
            initAddAanwer();
        }

        //隐藏新增答案窗口
        $scope.hideaddans = function() {
            $scope.showaddanswer = false;
        }

        //设置正确答案
        $scope.setTrueAnswer = function(subno){
            $scope.subjectitem.trueAnswer = subno;
        }

        $scope.changePageSize = function () {
            if (!$scope.setPageSize) {
                alert('不为空且最大不超过1000');
                $scope.setPageSize = $scope.config.pageSize;
            } else {
                $scope.config.pageSize = $scope.setPageSize;
            }
        };

        //保存题目
        $scope.saveSub = function() {
            if(!$scope.subjectitem.content) {
                alert("请填写试题内容!");
                return false;
            }
            var issubconemp = false;
            for(var i=0; i<$scope.answerarr.length; i++) {
                if(!$scope.answerarr[i].subcon) {
                    issubconemp = true;
                    break;
                }
            }
            if(issubconemp) {
                alert("题目答案内容不能为空!");
                return false;
            }
            if(!$scope.subjectitem.trueAnswer) {
                alert("请设置正确答案!");
                return false;
            }

            if($scope.answerarr.length<2){
                alert("请至少设置两个答案");
                return false;
            }


            $scope.subjectitem.answer = $scope.answerarr;

            var subForm = {}
            subForm.content = $scope.subjectitem.content;
            subForm.trueAnswer = $scope.subjectitem.trueAnswer;
            subForm.answer = angular.toJson($scope.subjectitem.answer);




            if(!$scope.subjectitem.shopSubjectId) {
                shopService.addShopSubject(subForm).then(function (json) {
                    //console.info(json)
                    $scope.showaddanswer = false;
                    initSearchData()
                })
            } else {
                subForm.shopSubjectId = $scope.subjectitem.shopSubjectId;
                shopService.updateShopSubject(subForm).then(function (json) {
                    //console.info(json)
                    $scope.showaddanswer = false;
                    initSearchData()
                })
            }

        }
    }

    //编辑
    $scope.editsubans = function(d) {
        $scope.showaddanswer = true;
        $scope.subjectitem = {}
        $scope.subjectitem.shopSubjectId = angular.copy(d.shopSubjectId);
        $scope.subjectitem.content = angular.copy(d.content);
        $scope.subjectitem.trueAnswer =  angular.copy(d.trueAnswer);
        $scope.answerarr =  angular.copy(d.answer);
    }

    $scope.deletesubans = function(d) {
        if(confirm("确认删除吗？")) {
            var subForm = {};
            subForm.shopSubjectId = d.shopSubjectId;
            shopService.deleteShopSubject(subForm).then(function (json) {
                alert("删除成功！");
                initSearchData();
            })
        }
    }
}]);
faApp.controller('BehaviorCustregisterList',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 50,
        "pageNo" : 1,
        "getPt": $scope.getPt,
        "monthStart": $scope.monthStart,
        "monthEnd": $scope.monthEnd
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        $scope.loading = true;
        shopService.getCustregisterList($scope.config).then(function (json) {
            $scope.loading = false;
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.list = json.l;
                $scope.pager = json.pager;
                $scope.jcs = json.jcs;
                $scope.sfa = json.sfa;
                $scope.times = json.times;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };

    $scope.queryList = function () {
        $scope.config.getPt = $scope.getPt;
        $scope.config.monthStart = $scope.monthStart;
        $scope.config.monthEnd = $scope.monthEnd;
        $scope.config.pageNo = 1;
        initSearchData();
    }
}]);
faApp.controller('BehaviorCruxdataList',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1,
        "monthStart" : $scope.monthStart,
        "monthEnd" : $scope.monthEnd
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        shopService.getCruxdataList($scope.config).then(function (json) {

            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.list = json.list;
                $scope.pager = json.pager;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };

    $scope.queryList = function () {
        $scope.config.monthStart = $scope.monthStart;
        $scope.config.monthEnd = $scope.monthEnd;
        initSearchData();
    }

}]);

faApp.controller('ShopInformationAddCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseCtrl', {$scope: $scope});

    var information = {};
    $scope.information = information;
    information.item = {};

    //初始化
    information.item.type = '1';
    information.item.upStatus = '1';
    information.item.pushMeg = '2';

    $scope.minDate = $filter('date')(new Date(), 'yyyy-MM-dd HH:mm');

    //保存
    $scope.save = function () {
        if($scope.information.item.type=='3') {
            if(!information.item.hotImg) {
                return false;
            }
            if(!information.item.commentHeaderurl) {
                return false;
            }
        }
        if ($scope.form.$invalid){
            if ($scope.form.title.$invalid)$scope.form.title.$dirty = true;
            if($scope.information.item.type != '4') {
                if ($scope.form.birefDesc.$invalid) $scope.form.birefDesc.$dirty = true;
            }
            if ($scope.form.type.$invalid)$scope.form.type.$dirty = true;
            if($scope.information.item.type == '2') {
                if ($scope.form.articleLink.$invalid) $scope.form.articleLink.$dirty = true;
            }
            if($scope.information.item.type != '2') {
                if ($scope.form.content.$invalid) $scope.form.content.$dirty = true;
            }
            if($scope.information.item.type=='3') {
                if ($scope.form.commentName.$invalid) $scope.form.commentName.$dirty = true;
                // if ($scope.form.commentHeaderurl.$invalid) $scope.form.commentHeaderurl.$dirty = true;
                if ($scope.form.commentIdentity.$invalid) $scope.form.commentIdentity.$dirty = true;
                if ($scope.form.commentPosition.$invalid) $scope.form.commentPosition.$dirty = true;
                if ($scope.form.commentContent.$invalid) $scope.form.commentContent.$dirty = true;
            }
            if ($scope.form.pushMeg.$invalid)$scope.form.pushMeg.$dirty = true;
            if ($scope.form.upStatus.$invalid)$scope.form.upStatus.$dirty = true;
        }else {
            var subForm = {}
            subForm = angular.copy(information.item);
            if(subForm.preTime) {
                subForm.preTime += ":00";
            }

            shopService.getShopInformationAdd(subForm).then(function (json) {
                $location.path('/shop/information/list')
            })
        }
    }

    $scope.onUploadFile({
        showMessage : function(m){ alert(m); },
        onComplete:function(f,response, id){
            id--;
            if (response.statusCode == "0000") {
                if(id==0) {
                    information.item.hotImg = App.staticHost + response.attribute.fileUrl;
                } else if(id==1) {
                    information.item.commentHeaderurl = App.staticHost + response.attribute.fileUrl;
                }
                $scope.$apply();
            } else {
                alert('上传失败');
            }
        }
    });

}]);
faApp.controller('ShopInformationEditCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseCtrl', {$scope: $scope});

    var id = $routeParams.id;
    console.info(id)

    var information = {};
    $scope.information = information;
    information.item = {};
    information.item.id = id;

    $scope.minDate = $filter('date')(new Date(), 'yyyy-MM-dd HH:mm');

    if(id) {
        shopService.getShopInformationDetail(id).then(function (json) {
            information.item = json.dto;
            information.item.preTime = $filter('date')(information.item.preTime, "yyyy-MM-dd HH:mm");
        })
    }

    //保存
    $scope.save = function () {
        if ($scope.form.$invalid){
            if ($scope.form.title.$invalid)$scope.form.title.$dirty = true;
            if($scope.information.item.type != '4') {
                if ($scope.form.birefDesc.$invalid) $scope.form.birefDesc.$dirty = true;
            }
            if ($scope.form.type.$invalid)$scope.form.type.$dirty = true;
            if($scope.information.item.type == '2') {
                if ($scope.form.articleLink.$invalid) $scope.form.articleLink.$dirty = true;
            }
            if($scope.information.item.type != '2') {
                if ($scope.form.content.$invalid) $scope.form.content.$dirty = true;
            }
            if($scope.information.item.type=='3') {
                if ($scope.form.commentName.$invalid) $scope.form.commentName.$dirty = true;
                if ($scope.form.commentHeaderurl.$invalid) $scope.form.commentHeaderurl.$dirty = true;
                if ($scope.form.commentIdentity.$invalid) $scope.form.commentIdentity.$dirty = true;
                if ($scope.form.commentPosition.$invalid) $scope.form.commentPosition.$dirty = true;
                if ($scope.form.commentContent.$invalid) $scope.form.commentContent.$dirty = true;
            }
            if ($scope.form.pushMeg.$invalid)$scope.form.pushMeg.$dirty = true;
            if ($scope.form.upStatus.$invalid)$scope.form.upStatus.$dirty = true;
        }else {
            var subForm = {}
            subForm = angular.copy(information.item);
            subForm.releaseTime = $filter('date')(subForm.releaseTime, 'yyyy-MM-dd HH:mm:ss');
            if(subForm.preTime) {
                subForm.preTime += ":00";
            }

            shopService.getShopInformationEdit(subForm).then(function (json) {
                $location.path('/shop/information/list')
            })
        }
    }

    $scope.onUploadFile({
        showMessage : function(m){ alert(m); },
        onComplete:function(f,response,id){
            id--;
            if (response.statusCode == "0000") {
                if(id==0) {
                    information.item.hotImg = App.staticHost + response.attribute.fileUrl;
                } else if(id==1) {
                    information.item.commentHeaderurl = App.staticHost + response.attribute.fileUrl;
                }
                $scope.$apply();
            } else {
                alert('上传失败');
            }
        }
    });

}]);
faApp.controller('ShopInformationListCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1,
        "type": $scope.type,
        // "releaseTimeStart": $scope.releaseTimeStart
        // "releaseTimeEnd": $scope.releaseTimeEnd
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        shopService.getShopInformationList($scope.config).then(function (json) {

            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.list = json.list;
                $scope.pager = json.pager;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };

    //查询
    $scope.queryList = function () {
        $scope.config.type = $scope.type;
        // $scope.config.releaseTimeStart = $scope.releaseTimeStart;
        // $scope.config.releaseTimeEnd = $scope.releaseTimeEnd;
        initSearchData();
    }

    //删除
    $scope.deleteInformation= function(id){
        if(id){
            if(confirm('确定要删除吗！')){
                shopService.getShopInformationDelete({id: id}).then(function(json){
                    if (json.statusCode){
                        alert(json.statusCode);
                    }else{
                        $route.reload();
                    }
                });
            }
        }
    }

    //上下架
    $scope.upordownInfo = function (id, status) {
        var subForm = {}
        subForm.id = id;
        subForm.upStatus = status;

        shopService.upordownInformation(subForm).then(function (json) {
            alert("操作成功!");
            $route.reload();
        })
    }
}]);

faApp.controller('jcsYxtActivityCount',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});
    $scope.loading = true;
    $scope.config={
        'monthStart':$scope.monthStart,
        'monthEnd':$scope.monthEnd
    }
    var initSearchData =function () {
        shopService.jcsYxtActivityCount($scope.config).then(function (json) {
            console.log(json)
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.news = json.news;
                $scope.newsRole = json.newsRole;
                $scope.allIn = json.allIn;
            }
        });
    }
    initSearchData();

    $scope.search = function () {
        $scope.config.monthStart = $scope.monthStart;
        $scope.config.monthEnd = $scope.monthEnd;
        initSearchData();
    }

}]);
faApp.controller('jcsYxtActivityDrawCount',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.activityCode = 'JCSYXT';//默认查英雄帖活动
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1,
        "mobile":$scope.mobile,
        "activityCode":$scope.activityCode
    }
    var initSearchData =function () {
        shopService.jcsYxtActivityDrawCount($scope.config).then(function (json) {
            console.log(json)
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.all = json.all;
                $scope.list = json.news;
                $scope.now = json.now;
                $scope.pager = json.page;
            }
        });
    }
    initSearchData();

    $scope.search = function () {
        $scope.config.mobile = $scope.mobile;
        $scope.config.activityCode = $scope.activityCode;
        initSearchData();
    }

    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
        initSearchData();
    };
    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
            initSearchData();
        } else {
            $scope.config.pageSize = $scope.setPageSize;
            initSearchData();
        }
    };
}]);


faApp.controller('pcTotalDynamic',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});
    $scope.loading = true;

    $scope.save =function () {

        shopService.pcTotalDynamicUpdate({"allUser":$scope.total.allUser,"allCooperation":$scope.total.allCooperation,"allAmount":$scope.total.allAmount})
            .then(function (json) {
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                alert("修改成功")
            }

        });
    }


    var initSearchData =function () {
        shopService.pcTotalDynamic().then(function (json) {
            console.log(json)
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.allAmounts = json.allAmount;
                $scope.allUsers = json.allUser;
                $scope.total = json.dto;
            }
        });
    }
    initSearchData();

}]);



faApp.controller('playOpenApplyList',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});
    $scope.loading = true;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1
    }

    $scope.save =function (cg,id) {

        shopService.playOpenApplyEdit({"id":id,"qStatus":cg})
            .then(function (json) {
                if (json.statusCode) {
                    alert("出错了:" + json.statusCode);
                } else {
                    alert("修改成功")
                    initSearchData()
                }

            });
    }


    var initSearchData =function () {
        shopService.playOpenApplyList($scope.config).then(function (json) {
            console.log(json)
            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {

                $scope.list = json.list;
                $scope.pager = json.pager;
            }
        });
    }
    initSearchData();

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
        initSearchData();
    };
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
        initSearchData();
    };
    $scope.search = function () {

        $scope.config.qStatus = $scope.qStatus;
        initSearchData();
    }
}]);

faApp.controller('shopInfoListCtrl',['$rootScope','$scope','shopService','$location','$controller','$routeParams','$route','$cookies','$timeout','$filter',function($rootScope,$scope,shopService,$location,$controller,$routeParams,$route,$cookies,$timeout, $filter) {
    $controller('BaseListCtrl', {$scope: $scope});

    $scope.list = [];
    $scope.loading = true;
    $scope.config={
        "pageSize" : 20,
        "pageNo" : 1,
        "deleteTag": '1',
        "shopPhone": $scope.shopPhone,
        "shopName": $scope.shopName
    }
    $scope.pageChanged = function(){
        $scope.config.pageNo = $scope.pager.pageNo;
    };

    function initSearchData() {
        shopService.getShopInfoList($scope.config).then(function (json) {

            if (json.statusCode) {
                alert("出错了:" + json.statusCode);
            } else {
                $scope.list = json.list;
                $scope.pager = json.pager;

                $scope.setPageSize = $scope.pager.pageSize;
            }
        });
    }

    $scope.$watch('config',function(){
        if ($scope.watchIsChange()) {
            initSearchData();
        }
    },true);

    $scope.changePageSize = function () {
        if (!$scope.setPageSize) {
            alert('不为空且最大不超过1000');
            $scope.setPageSize = $scope.config.pageSize;
        } else {
            $scope.config.pageSize = $scope.setPageSize;
        }
    };

    //查询
    $scope.queryList = function () {
        $scope.config.shopPhone = $scope.shopPhone;
        $scope.config.shopName = $scope.shopName;
        initSearchData();
    }

    //新增
    $scope.showAddShopInfoWin = false;
    $scope.addOrEditShopInfo = function () {
        $scope.showAddShopInfoWin = true;
    }

    //删除
    $scope.deleteInformation= function(id){
        if(id){
            if(confirm('确定要删除吗！')){
                shopService.updateShopInfo({id: id, deleteTag: "2"}).then(function(json){
                    if (json.statusCode){
                        alert(json.statusCode);
                    }else{
                        $route.reload();
                    }
                });
            }
        }
    }

    $scope.editInformation= function(data){
        $scope.showAddShopInfoWin = true;
        $scope.item = data;
    }

    //保存
    $scope.item = {};
    $scope.shopInfoSave = function () {
        if($scope.item.id) {
            shopService.updateShopInfo($scope.item).then(function (json) {
                $scope.showAddShopInfoWin = false;
                alert('保存成功！');
                initSearchData();

                $scope.item = {};
            });
        } else {
            shopService.addShopInfo($scope.item).then(function (json) {
                $scope.showAddShopInfoWin = false;
                alert('保存成功！');
                initSearchData();

                $scope.item = {};
            });
        }
    }
}]);